﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DAL;

namespace BLL
{
    public class ForAdvance
    {
        //查询登录读者的读者ID
        public string SelectReaderID()
        {
            string sql = string.Format(@"select ReaderName from Reader where ReaderID = {0}", StaticStore.readerID);
            string readerName = DBHelper.ExecuteScalar(sql).ToString();
            return readerName;
        }
        //插入预借记录
        public int AddReserve(string BookID,string ReaderID)
        {
            StringBuilder sb = new StringBuilder();
            //编写SQL语句，进行添加操作
            sb.AppendFormat(@"insert into Reserve(BookID,ReaderID,RDate) values('{0}','{1}',GETDATE())",
                        Convert.ToInt32(BookID), Convert.ToInt32(ReaderID));
            //进行增删改查使用ExecuteNonQuery（）方法
            int i = DBHelper.ExecuteNonQuery(sb.ToString());
            return i;
        }
        //更新预定状态
        public int AlterBookState(string BookState,string BookID)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat(@"update Books set StateID = {0} where BookID = {1}", Convert.ToInt32(BookState), Convert.ToInt32(BookID));
            int i = DBHelper.ExecuteNonQuery(sb.ToString());
            return i;
        }
        //更新读者信息
        public int AlterReader()
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat(@"update Reader set BorrowBook = BorrowBook - 1,ReturnBook = ReturnBook + 1 where ReaderID = {0};", Convert.ToInt32(StaticStore.readerID));
            int i = DBHelper.ExecuteNonQuery(sb.ToString());
            return i;
        }
    }
}
